/*
 * The MIT License
 *
 * Copyright 2014 Venkat Ram Akkineni.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.netbeans.modules.tfsnb.tfvc.workingfolder;

import com.microsoft.tfs.core.TFSTeamProjectCollection;
import com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient;
import java.awt.BorderLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JFileChooser;
import javax.swing.JProgressBar;
import javax.swing.JSplitPane;
import org.netbeans.modules.tfsnb.tfvc.workingfolder.filesystemtree.FileSystemTreePanel;
import org.netbeans.modules.tfsnb.tfvc.workingfolder.treeview.WorkingFolderServerItemTreeViewPanel;
import org.netbeans.modules.tfsnb.tfvc.workspace.WorkingFoldersMappingsPanel;

/**
 *
 * @author Venkat Ram Akkineni
 */
public class NewWorkingFolderMappingPanel extends javax.swing.JPanel implements PropertyChangeListener {
    
    /**
     * Creates new form NewWorkingFolderMappingPanel
     */
    public NewWorkingFolderMappingPanel(final VersionControlClient vcc,
            final TFSTeamProjectCollection teamProjectCollection) {
        this.versionControlClient = vcc;
        this.teamProjectCollection = teamProjectCollection;
        initComponents();
        horizontalSplitPane.setDividerLocation(0.5d);
        verticalSplitPane.setDividerLocation(0.8d);
        addWorkingFolderServerItemTreeViewPanel(vcc, teamProjectCollection);
        addFileChooserPanel();
        addWorkingFoldersMappingsPanel();
        progressBar = new JProgressBar(0, 100);
        progressBar.setValue(0);
        add(progressBar, BorderLayout.PAGE_END);
    }
    
    private void addWorkingFolderServerItemTreeViewPanel(final VersionControlClient vcc,
            final TFSTeamProjectCollection teamProjectCollection) {
        treeViewPanel = new WorkingFolderServerItemTreeViewPanel(vcc, teamProjectCollection);
        treeViewPanel.addPropertyChangeListener("showProgressBar", this);
        treeViewPanel.buildServerFolderExplorerManager();
        horizontalSplitPane.add(treeViewPanel, JSplitPane.LEFT);
    }
    
    private void addFileChooserPanel() {
//        fileChooser = new JFileChooser();
//        fileChooser.setControlButtonsAreShown(false);
        final FileSystemTreePanel fileSystemTreePanel = new FileSystemTreePanel();
        horizontalSplitPane.add(fileSystemTreePanel, JSplitPane.RIGHT);
    }
    
    private void addWorkingFoldersMappingsPanel() {
        workingFoldersMappingsPanel = new WorkingFoldersMappingsPanel(versionControlClient, teamProjectCollection);
        verticalSplitPane.add(workingFoldersMappingsPanel, JSplitPane.BOTTOM);
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
     * content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        verticalSplitPane = new javax.swing.JSplitPane();
        horizontalSplitPane = new javax.swing.JSplitPane();

        setLayout(new java.awt.BorderLayout());

        verticalSplitPane.setDividerSize(5);
        verticalSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        verticalSplitPane.setResizeWeight(0.7);
        verticalSplitPane.setMinimumSize(new java.awt.Dimension(800, 450));
        verticalSplitPane.setPreferredSize(new java.awt.Dimension(800, 450));

        horizontalSplitPane.setDividerSize(5);
        horizontalSplitPane.setResizeWeight(0.5);
        verticalSplitPane.setTopComponent(horizontalSplitPane);

        add(verticalSplitPane, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents


    private VersionControlClient versionControlClient;
    private TFSTeamProjectCollection teamProjectCollection;
    private WorkingFolderServerItemTreeViewPanel treeViewPanel;
    private WorkingFoldersMappingsPanel workingFoldersMappingsPanel;
    private JFileChooser fileChooser;
    private final JProgressBar progressBar;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSplitPane horizontalSplitPane;
    private javax.swing.JSplitPane verticalSplitPane;
    // End of variables declaration//GEN-END:variables

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        final boolean val = (boolean) evt.getNewValue();
        progressBar.setIndeterminate(val);
        progressBar.setStringPainted(val);
    }
}
